<template>
  <div class="oe-ruleEdit oe-test-paper" v-loading="loading">
    <topTip
      v-if="!stepMode && batchTitle"
      :batchTitle="batchTitle"
      :examTitle="examTitle"
      :title="title"
    ></topTip>
    <div class="oe-ruleEdit-content">
      <div class="oe-tab-box">
        <a-popconfirm
          class="test-hint-exe"
          placement="top"
          :disabled="!paperType.length || isAdd || examType == 0"
          ok-text="是"
          cancel-text="否"
          @confirm="getTab(0)"
        >
          <template slot="title">
            <p>确定要切换试卷吗？</p>
            <p>切换试卷后将清除当前页没有保存的内容</p>
          </template>
          <div
            v-if="!paperType.length || isAdd"
            class="oe-tab-lis"
            :class="{ 'oe-tab-activate': examType == 0 }"
            @click="getTab(0)"
          >A卷</div>
          <div v-else class="oe-tab-lis" :class="{ 'oe-tab-activate': examType == 0 }">A卷</div>
        </a-popconfirm>
        <a-popover v-if="!isAdd && examType !== 1" title="温馨提示!" trigger="click">
          <template slot="content">
            <p>请先设置A卷后才能设置 B 卷!</p>
          </template>
          <div
            class="oe-tab-lis"
            :class="{ 'oe-tab-activate': examType == 1 }"
            style="border-left: 1px solid #D9D9D9;"
          >B卷</div>
        </a-popover>
        <div
          v-else
          class="oe-tab-lis"
          :class="{ 'oe-tab-activate': examType == 1 }"
          @click="getTab(1)"
          style="border-left: 1px solid #D9D9D9;"
        >B卷</div>
      </div>
      <div class="set-testpaper-container">
        <span class="set-testpaper-label">出题方式：</span>
        <a-radio-group
          name="radioGroup"
          v-model="mode"
          @change="getModeType"
          :disabled="onlyQuesRead"
        >
          <a-radio :disabled="editDisabled && mode !== 0" :value="0">随机出题</a-radio>
          <a-radio :disabled="editDisabled && mode !== 1" :value="1">出卷规则选择</a-radio>
          <a-select
            style="width: 150px; height: 30px; margin-right: 20px"
            :value="undefined"
            :placeholder="randomPlaceholder"
            labelInValue
            :disabled="onlyQuesRead || (mode != 1 || !isCanEdit)"
            @change="onChangeRulesOptions"
          >
            <a-select-option
              v-for="item in ruleList"
              :key="item.Id"
              :label="item.Title"
              :value="item.Id"
            >{{ item.Title }}</a-select-option>
          </a-select>
          <a-radio :disabled="editDisabled && mode !== 2" :value="2">固定出题</a-radio>
        </a-radio-group>
        <!-- <a-button type="primary" v-if="!editDisabled && !onlyQuesRead" @click="importworddQues">Word导入</a-button> -->
        <a-select
          style="width: 160px; height: 30px; margin-right: 20px"
          :value="undefined"
          :placeholder="fixedPlaceholder"
          labelInValue
          :disabled="onlyQuesRead || (mode != 2 || !isCanEdit)"
          @change="importworddQues"
        >
          <a-select-option
            v-for="item in selectData"
            :key="item.Id"
            :title="item.Title"
            :label="item.Title"
            :value="item.Id"
          >{{ item.Title }}</a-select-option>
        </a-select>
      </div>
      <div class="oe-ruleEdit-set">
        <div class="set-ruleEdit-container">
          <div
            class="set-container"
            :class="{ 'container-labelShow': labelShow }"
            style="overflow: hidden;"
          >
            <span class="set-ruleEdit-label">题目分类：</span>
            <a-checkbox-group v-model="paperType" style="width: calc(100% - 157px);">
              <a-row>
                <a-col
                  style="line-height: 30px; float: left; min-width: 12%;"
                  v-for="item in paperTypeList"
                  :key="item.Id"
                >
                  <a-checkbox
                    :disabled="(mode == 1 || !isCanEdit) || onlyQuesRead"
                    :value="item"
                  >{{ item.Name }}</a-checkbox>
                </a-col>
                <a-col
                  :span="3"
                  style="line-height: 30px;color:#1E8DFD;cursor: pointer;"
                  @click="visible = true"
                >
                  <router-link to="/teacher/questionManagement" target="_blank">
                    <span>
                      <a-icon type="plus-circle" />添加新分类
                    </span>
                  </router-link>
                </a-col>
              </a-row>
            </a-checkbox-group>
            <span
              class="set-ruleEdit-label label-btn"
              @click="getCheckbox"
              v-if="paperTypeList.length > 0"
            >
              <i class="iconfont icon-zhankai1" :class="{ 'btn-labelShow': labelShow }"></i>
              {{ btnTitle }}
            </span>
          </div>
        </div>
        <div class="set-ruleEdit-container">
          <span class="set-ruleEdit-label">多选题计分方式：</span>
          <a-radio-group
            name="radioGroup"
            :disabled="(mode == 1 || !isCanEdit) || onlyQuesRead"
            v-model="way"
          >
            <a-radio :value="1">多选、少选、错选不得分</a-radio>
            <a-radio :value="2">少选时，按照选项个数计分</a-radio>
            <a-radio :value="3">少选时，得一半分数</a-radio>
          </a-radio-group>
        </div>
      </div>
    </div>
    <question-type
      v-if="mode !== 2"
      :title="titleType"
      :saveTitle="stepMode ? (sysType==2 ? '保存试卷并返回' : '保存试卷并下一步') : '保存试卷'"
      :cancelTitle="'取消'"
      :disabled="(mode == 1 || !isCanEdit) || onlyQuesRead"
      :isCanEdit="onlyQuesRead || !isCanEdit"
      :listeningTrigger="listeningTrigger"
      :courseNameList="paperType"
      :paperNumber="paperNumber"
      :examScore="totalScore"
      @onChangeCondition="getQuesTypeCount"
      @onSave="onSave"
      @onCancel="onCancel"
    ></question-type>
    <question-type-exam
      v-if="mode == 2"
      :title="titleType"
      :saveTitle="stepMode ? (sysType==2 ? '保存试卷并返回' : '保存试卷并下一步') : '保存试卷'"
      :cancelTitle="'取消'"
      :disabled="(mode == 1 || !isCanEdit) || onlyQuesRead"
      :isCanEdit="onlyQuesRead || !isCanEdit"
      :listeningTrigger="listeningTrigger"
      :courseNameList="paperType"
      :handDisplayData="setNumber"
      :examScore="totalScore"
      :importIconUse="importIconUse"
      @onSave="onSave"
      @onCancel="onCancel"
      @onModification="onModification"
      @onChangeScore="onChangeScore"
    ></question-type-exam>
    <div v-if="stepMode" style="display: flex;justify-content: space-around;padding: 0 600px;">
      <a-button type="primary" @click="$parent.previousStep()">上一步</a-button>
      <a-button v-if="isQues" type="primary" style="margin: 0px 15px;" @click="watchExam">预览试卷</a-button>
      <a-button v-if="isQues && sysType != 2" type="primary" @click="$parent.nextStep()">下一步</a-button>
    </div>
    <!-- 文件导入 -->
    <a-modal
      :title="importTitle"
      class="oe-student"
      :visible="importword"
      width="40%"
      @cancel="importedCancelword"
    >
      <div class="oe-select">
        <span v-if="wordImportType===2 || wordImportType===5" class="oe-manage-select">
          <h2>注意事项：</h2>
          <div>1、导入前建议先查看下载模板中的示例，按要求添加导入信息</div>
          <div>2、请按照模板规范顺序导入数据</div>
          <div>3、标红列为必填项</div>
        </span>
        <span v-else-if="wordImportType===3 || wordImportType===6" class="oe-manage-select">
          <h2>注意事项：</h2>
          <div>1、下载试卷导入模板,按要求添加导入信息</div>
          <div style="color:red;">2、考试结束后在考试管理页面点击同步答案，将题目同步到题库，才能批阅（建议考试结束后进行）</div>
        </span>
      </div>
      <div class="oe-select">
        <a
          href="/exam/excel/试卷导入模板.docx"
          v-if="wordImportType===2 || wordImportType===3"
          target="_blank"
        >下载模板</a>
        <a
          href="/exam/excel/试卷导入模板.xls"
          v-if="wordImportType===5 || wordImportType===6"
          target="_blank"
        >下载模板</a>
      </div>
      <div>
        <div class="clearfix">
          <a-upload
            :fileList="fileListword"
            :remove="handleRemoveword"
            :beforeUpload="beforeUploadword"
            :accept="wordImportType < 4 ? '.docx': '.xlsx,.xls' "
          >
            <a-button>
              <a-icon type="upload" />选择文件
            </a-button>
          </a-upload>
        </div>
      </div>
      <div class="oe-select-table">
        <a-table
          :columns="errorColumns"
          :dataSource="errorListword"
          :pagination="false"
          v-if="errorListword.length > 0"
        ></a-table>
      </div>
      <template slot="footer">
        <a-button
          type="primary"
          @click="handleUploadword"
          :disabled="fileCountword === 0"
          :loading="uploading"
          style="margin-top: 16px"
        >{{ uploading ? '上传中' : '上传' }}</a-button>
        <a-button @click.stop="importedCancelword">取消</a-button>
      </template>
    </a-modal>
    <!-- 手动出题 -->
    <div id="components-modal-demo-position">
      <a-modal
        :title="modalTitle"
        width="70%"
        :visible="modalVisible"
        :ok-button-props="{ props: { disabled: !selectedRowKeys.length && isShowAddQuestion } }"
        @ok="() => onModalVisible('ok', isShowAddQuestion)"
        @cancel="() => onModalVisible('cancel', isShowAddQuestion)"
      >
        <div v-if="isShowAddQuestion">
          <div style="margin-bottom: 20px">
            <span class="set-ruleEdit-label">难度：</span>
            <a-select
              style="width: 150px; height: 30px; margin-right: 20px"
              :placeholder="selectPlaceholder"
              labelInValue
              :value="undefined"
              @change="onChangeDifficulty"
            >
              <a-select-option
                v-for="item in difficulty"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >{{ item.label }}</a-select-option>
            </a-select>
            <!-- <span class="set-ruleEdit-label">知识点：</span>
            <a-select
              mode="multiple"
              :placeholder="selectKnowledgePlaceholder"
              style="width: 300px; margin-right: 20px"
              :value="handKnowledgeId"
              @change="onChangeKnowledge"
            >
              <a-select-option
                v-for="item in handKnowledgeList"
                :key="item.KnowledgeId"
                :value="item.KnowledgeId"
              >{{ item.KnowledgeTitle }}</a-select-option>
            </a-select> -->
            <span class="set-ruleEdit-label">搜索：</span>
            <a-input-search
              placeholder="搜索"
              v-model="searchValue"
              style="width: 200px"
              @search="getQuestionsList"
            />
          </div>
          <div style="display: table;width: 100%;" v-if="isShowAddQuestion">
            <div style="display: table-cell;width: 300px;border-right: 1px solid #ccc;">
              <div class="clearfix" style="border-left: 5px solid #1890ff;">
                <span class="fl" style="line-height: 30px;font-size: 18px;font-weight: bold;margin-left: 10px;">知识点</span>
                <!-- <a-button type="primary" class="fr" style="margin-right: 10px;" @click="getTreeQuetion">查询</a-button> -->
              </div>
              <div style="height: 920px;overflow: auto;">
                <div v-for="(item, index) in manualList" :key="index">
                  <div style="background: #f1f3f4;border: 1px solid #ccc;margin: 6px 5px 0px;padding: 5px;font-size: 16px;cursor: pointer;" @click="getTreeShow(index)">
                    <div style="display:inline-block;">{{item.Name}}</div>
                    <a-icon type="down" class="fr" style="line-height: 26px;" v-if="item.treeShow"/>
                    <a-icon type="right" class="fr" style="line-height: 26px;" v-else/>
                  </div>
                  <div v-show="item.treeShow" style="padding: 5px;">
                    <tree-select :width="'300px'" ref="tree" :list="item.list" @change="getTreeQuetion"></tree-select>
                  </div>
                </div>
              </div>
            </div>
            <div style="display: table-cell;width: calc(100% - 300px);">
              <a-table
                :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                :columns="columns"
                :dataSource="questionsList"
              >
                <span
                  class="table-extend"
                  slot="TitleText"
                  slot-scope="text, record"
                  v-html="record.Title"
                ></span>
              </a-table>
            </div>
          </div>
        </div>
        <a-table
          v-if="!isShowAddQuestion"
          :columns="pitchOnColumns"
          :dataSource="selectList"
          :pagination="false"
        >
          <span
            class="table-extend"
            slot="TitleText"
            slot-scope="text, record"
            v-html="record.Title"
          ></span>
          <span
            class="table-extend"
            slot="DefficultyLevel"
            slot-scope="text, record"
          >{{setLevel(record.DefficultyLevel)}}</span>
          <span slot="QuesScore" slot-scope="text, record">
            <a-input-number :min=0 v-model="record.QuesScore" placeholder="填写分值" />
          </span>
          <span slot="action" slot-scope="record, index, indent, expanded">
            <a-tooltip placement="bottom" title="删除">
              <span @click.stop="onDelRule(record, index, indent, expanded)" class="delete-icon">
                <i class="iconfont icon-delete"></i>
              </span>
            </a-tooltip>
          </span>
        </a-table>
      </a-modal>
    </div>
    <a-modal
      title="温馨提示"
      :visible="hintVisible"
      :confirm-loading="confirmLoading"
      @ok="hintVisible = false"
      @cancel="hintVisible = false"
    >
      <p>请选好题目分类后 - 再设置题目规则, 否则新增题目分类，会清空已设置的题目</p>
    </a-modal>
    <a-modal
      title="word导入检查"
      class="oe-student"
      :visible="importwordCheck"
      width="70%"
      @cancel="importwordCheck=false"
    >
      <div class="div-newImportQues">
        <div class="oe-select check_div">
          <div>
            <span class="title-h">输入区</span>
            <a-button
              type="primary"
              @click="checkWord"
              style="float: right;margin-right: 20px;"
            >{{ uploading ? '检查中' : '检查' }}</a-button>
          </div>
          <div class="over-div">
            <p>
              <b>试题分类：</b>
              <a-input v-model="courseName" style="width:85%" placeholder="请输入试题分类" />
            </p>
            <h2>试卷设置</h2>
            <table>
              <tr>
                <th>题型</th>
                <th>题目个数</th>
                <th>默认分值</th>
                <th>操作</th>
              </tr>
              <tr v-for="(item,i)  in listSocre" :key="i">
                <td>
                  <a-input v-model="item.Title" style="width:85%" placeholder="请输入题型" />
                </td>
                <td>
                  <a-input-number
                    v-model="item.Num"
                    :min="0"
                    :max="100"
                    style="width:85%"
                    placeholder="请输入题目个数"
                  />
                </td>
                <td>
                  <a-input-number
                    :min="0"
                    :step="0.1"
                    :max="300"
                    v-model="item.Score"
                    style="width:85%"
                    placeholder="请输入默认分值"
                  />
                </td>
                <td>
                  <span slot="action" style="cursor: pointer;" v-show="listSocre.length > 1">
                    <a-tooltip placement="bottom" title="删除">
                      <span @click.stop="del(i)" class="delete-icon">
                        <i class="iconfont icon-delete"></i>
                      </span>
                    </a-tooltip>
                  </span>
                </td>
              </tr>
            </table>
            <span  class="add_quesType" @click="add()" v-show="listSocre.length < 6" >
              <a-icon type="plus-circle" />添加题型
            </span>
            <h2 style="margin-top: 25px;">试卷内容</h2>
            <div contenteditable="true">
              <p v-for="(item,i)  in listCheck" :key="i" ref="checkBox">
                <span v-html="item"></span>
                <br v-if="!item" />
              </p>
            </div>
          </div>
        </div>
        <div class="import_div">
          <div>
            <span class="title-h">检查区</span>
            <span v-if="errorNum > 0" class="error-span">识别错误：{{errorNum}}处。请检查！</span>
          </div>
          <div class="over-div">
            <p>
              <b>试题分类：</b>
              {{courseName}}
            </p>
            <h2>
              试卷设置
              <em v-if="totleError" class="error-em">{{totleError}}</em>
            </h2>
            <table>
              <tr>
                <th>题型</th>
                <th>题目个数</th>
                <th>默认分值</th>
                <th>总分数</th>
                <th>提示</th>
              </tr>
              <tr v-for="(item,i)  in listSocre_check" :key="i">
                <td>{{item.Title}}</td>
                <td>{{item.Num}}</td>
                <td>{{item.Score}}</td>
                <td>{{item.TotleScore}}</td>
                <td :class="item.Error ? 'error-td' : ''">
                  <span v-if="item.Error">{{item.Error}}</span>
                </td>
              </tr>
            </table>
            <h2>试卷内容</h2>
            <div v-for="(item,i) in questions" :key="i">
              <div>
                <b>
                  <strong>{{i+1}}、{{item.QuestionType}}</strong>
                </b>
                <span v-html="item.Title"></span>
              </div>
              <div v-if="item.QuestionType == '单选题' || item.QuestionType == '多选题'">
                <span v-for="(option,c) in item.Options" :key="c">
                  <p v-if="option">
                    <b>
                      <strong>{{Alphabet[c]}}、</strong>
                    </b>
                    <span v-html="option"></span>
                  </p>
                </span>
              </div>
              <div>
                <p>
                  <span class="ques-weight">难度:</span>
                  {{item.Difficulty}}
                </p>
                <p>
                  <span class="ques-weight">知识点:</span>
                  {{item.Knowledge}}
                </p>
                <p>
                  <span class="ques-weight">答案:</span>
                  <span v-html="item.Answer"></span>
                </p>
                <p>
                  <span class="ques-weight">解析:</span>
                  <span v-html="item.Resolution"></span>
                </p>
                <p class="error_span" data-id="i" v-if="item.Error">
                  <span class="ques-weight">错误:</span>
                  <span v-html="item.Error"></span>
                </p>
              </div>
              <div></div>
              <div class="next-ques"></div>
            </div>
          </div>
        </div>
      </div>
      <div>
        <div class="clearfix"></div>
      </div>
      <template slot="footer">
        <a-button
          type="primary"
          @click="upWord"
          :disabled="errorNum > 0"
          :loading="uploading"
          style="margin-top: 16px"
        >{{ uploading ? '导入中' : '导入' }}</a-button>
        <a-button @click.stop="importwordCheck=false">取消</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script>
import topTip from '@/components/top-tip/index.vue';
import questionType from '@/components/question-type/index.vue';
import questionTypeExam from '@/components/question-type/exam.vue';
import GetOperationList from '@/lib/mixin/methods.js';
import treeSelect from '@/components/treeSelect/index.vue';
export default {
  mixins: [GetOperationList],
  components: {
    topTip,
    questionType,
    questionTypeExam,
    treeSelect
  },
  data() {
    return {
      Alphabet: [
        'A',
        'B',
        'C',
        'D',
        'E',
        'F',
        'G',
        'H',
        'I',
        'J',
        'K',
        'L',
        'M',
        'N',
        'O',
        'P',
        'Q',
        'R',
        'S',
        'T',
        'U',
        'V',
        'W',
        'X',
        'Y',
        'Z'
      ],
      titleType: '随机出题',
      mode: 0,
      editDisabled: false, // true 编辑  false // 添加
      isCanEdit: true, // 试卷已启用禁止编辑 true 可以编辑 false 禁止编辑
      examType: 0,
      randomPlaceholder: '从规则中选择',
      loading: false,
      title: [{ text: '设置试卷' }],
      examId: '', // 考试Id
      randomExamRuleId: '', // 题目分类Id
      paperTypeList: [], // 题目分类列表
      paperType: [], // 选中的题目分类列表
      rulesDetails: [], // 详情
      ruleList: [], // 规则列表
      searchValue: '', // 考题筛选
      selectPlaceholder: '', //手动考题筛选难度
      selectKnowledgePlaceholder: '', //手动考题筛选知识点
      questionsList: [], // 考题列表
      selectList: [], // 选中考题列表
      setNumber: [], //设置考题数据
      mergedList: [], // 暂存数据
      setNumberIndex: 0, //考题数据下标
      listeningTrigger: false, // 深度监听触发装置
      questionNumber: [], // 手动出题题目数量
      paperNumber: 1, // 试卷份数
      totalScore: 100, //试卷分数
      questionType: '',
      courseIds: [], // 题目分类id
      handKnowledgeId: [], // 手动出题知识点
      defficultyLevel: [],
      way: 1,
      labelShow: false,
      btnTitle: '展开',
      knowledge: '',
      hintVisible: false, // hint
      modalVisible: false, // modal
      modalTitle: '新增考题',
      isAdd: false, // 编辑状态
      selectedRowKeys: [],
      isShowAddQuestion: false, // true添加题目列表 || false已添加题目列表
      //word
      importedword: [],
      importword: false,
      fileListword: [],
      fileCountword: 0,
      errorListword: [],
      errorColumns: [
        {
          title: '序号',
          dataIndex: 'Number',
          align: 'center'
        },
        {
          title: '明细',
          dataIndex: 'Title',
          align: 'center'
        }
      ],
      // 手动知识点选项
      handKnowledgeList: [],
      // 手动难度选项
      difficulty: [
        { value: 0, label: '全部' },
        { value: 1, label: '非常简单' },
        { value: 2, label: '简单' },
        { value: 3, label: '一般' },
        { value: 4, label: '困难' },
        { value: 5, label: '非常困难' }
      ],
      // 题目列表
      columns: [
        {
          title: '题干',
          key: 'TitleText',
          dataIndex: 'TitleText',
          scopedSlots: { customRender: 'TitleText' },
          align: 'center'
        },
        {
          title: '所属课程',
          dataIndex: 'Name',
          align: 'center'
        },
        {
          title: '知识点',
          dataIndex: 'KnowledgeTitle',
          align: 'center'
        },
        {
          title: '难度',
          dataIndex: 'DefficultyLevel',
          align: 'center'
        }
      ],
      // 选中题目数量
      pitchOnColumns: [
        {
          title: '序号',
          dataIndex: 'Number',
          width: '10%',
          key: 'Number'
        },
        {
          title: '题干',
          key: 'TitleText',
          dataIndex: 'TitleText',
          scopedSlots: { customRender: 'TitleText' },
          align: 'center'
        },
        {
          title: '所属课程',
          dataIndex: 'Name',
          align: 'center'
        },
        {
          title: '知识点',
          dataIndex: 'KnowledgeTitle',
          align: 'center'
        },
        {
          title: '难度',
          key: 'DefficultyLevel',
          dataIndex: 'DefficultyLevel',
          scopedSlots: { customRender: 'DefficultyLevel' },
          align: 'center'
        },
        {
          title: '分数',
          key: 'QuesScore',
          width: '100px',
          dataIndex: 'QuesScore',
          scopedSlots: { customRender: 'QuesScore' },
          align: 'center'
        },
        {
          title: '操作',
          key: 'action',
          scopedSlots: { customRender: 'action' },
          align: 'center'
        }
      ],
      examTitle: '',
      batchTitle: '',
      operationList: [],
      onlyQuesRead: false,
      wordImportType: 0, // 0:随机出题 1:手动新增 2:Word有答案考试 3:Word无答案考试(导入时有答案) 4:Word无答案考试(导入时无答案),5:Excel有答案考试 6:Excel无答案考试(导入时有答案) 7:Excel无答案考试(导入时无答案)
      selectData: [
        { Id: 1, Title: '手动出题' },
        { Id: 2, Title: 'Word导入(显示答案)' },
        { Id: 3, Title: 'Word导入(不显示答案)' },
        { Id: 5, Title: 'Excel导入(显示答案)' },
        { Id: 6, Title: 'Excel导入(不显示答案)' }
      ],
      fixedPlaceholder: '从固定出题中选择',
      importwordCheck: false,
      listCheck: [],
      questions: [],
      errorNum: 0,
      wordDataJson: [],
      listSocre: [],
      listSocre_check: [],
      courseName: '',
      totleError: '',
      manualList: []
    };
  },
  props: {
    examid: {
      type: String,
      default: ''
    },
    stepMode: {
      type: Boolean,
      default: false
    },
    isQues: {
      type: Boolean,
      default: false
    },
    sysType: {
      type: Number,
      default: 0
    }
  },
  computed: {
    importTitle() {
      let title = '';
      switch (this.wordImportType) {
        case 2:
          title = 'Word导入(显示答案)';
          break;
        case 3:
          title = 'Word导入(不显示答案)';
          break;
        case 5:
          title = 'Excel导入(显示答案)';
          break;
        case 6:
          title = 'Excel导入(不显示答案)';
          break;
      }
      return title;
    },
    importIconUse() {
      if (this.wordImportType == 1) {
        //word导入类型
        return false;
      } else {
        return true;
      }
      // if (this.wordImportType === 2 || this.wordImportType === 3 ) {
      //   //word导入类型
      //   return false;
      // } else {
      //   return true;
      // }
    }
  },
  created() {
    this.getType();
  },
  watch: {
    paperType(newValue, oldValue) {
      if (newValue.length == 1) {
        if (this.operationList.includes('设置题目')) {
          if (this.onlyQuesRead) {
            this.hintVisible = true;
          } else {
            this.hintVisible = false;
          }
        } else {
          this.hintVisible = false;
        }
      }
      this.getFor(newValue);
    },
    mode(newValue) {
      this.titleType = newValue == 2 ? '固定出题' : '随机出题';
      this.wordImportType = newValue == 2 ? this.wordImportType : 0;
    },
    ruleList(newValue) {
      if (this.editDisabled == true) {
        let ruleTitle = newValue.filter((item) => item.Id === this.randomExamRuleId);
        this.randomPlaceholder = ruleTitle.length > 0 ? ruleTitle[0].Title : '从规则中选择';
      }
    }
  },
  methods: {
    setLevel(e) {
      for (let i = 0; i < this.difficulty.length; i++) {
        if (this.difficulty[i].value == e) {
          return this.difficulty[i].label
        }
      };
      return e
    },
    getTreeQuetion() {
      let KnowledgeList = [];
      for (let i = 0; i < this.manualList.length; i++) {
        console.log(this.$refs.tree[i].ids);
        KnowledgeList = KnowledgeList.concat(this.$refs.tree[i].ids);
      };
      this.handKnowledgeId = KnowledgeList;
      this.getQuestionsList();
    },
    getTreeShow(index) {
      console.log(index);
      this.manualList[index].treeShow = !this.manualList[index].treeShow;
      console.log(this.manualList[index].treeShow);
      this.$forceUpdate();
    },
    watchExam() {
      let newPage = this.$router.resolve({
        name: 'reviewPaper',
        params: {
          batchid: this.$route.params.batchid,
          examid: this.examid
        }
      });
      window.open(newPage.href, '_blank');
    },
    //获取试卷是否可编辑
    getPaperIsCanEdit() {
      var that = this;
      this.$http
        .post('/api/design/papermanage/getPaperIsCanEdit', {
          examId: this.examid,
          examType: this.examType
        })
        .then((res) => {
          if (res.code > 0) {
            that.isCanEdit = res.isCanEdit;
            that.hintVisible = res.isCanEdit;
          }
        });
    },
    //点击word导入
    importworddQues({ key, label }) {
      console.log(key, label, 8888);
      this.fileCountword = 0;
      this.wordImportType = key;
      this.fixedPlaceholder = label;
      this.errorListword = [];
      this.fileListword = [];
      if (key < 2) {
        this.paperType = [];
        return;
      }
      this.importword = true;
    },
    // 取消
    importedCancelword() {
      this.importword = false;
    },
    // 删除
    handleRemoveword(file) {
      const index = this.fileListword.indexOf(file);
      const newFileList = this.fileListword.slice();
      newFileList.splice(index, 1);
      this.fileListword = newFileList;
      this.errorListword = [];
    },
    //选择文件
    beforeUpload(file) {
      this.fileList = [];
      this.fileCount = 1;
      this.fileList = [...this.fileList, file];
      return false;
    },
    beforeUploadword(file) {
      this.fileListword = [];
      this.fileCountword = 1;
      this.fileListword = [...this.fileListword, file];
      return false;
    },
    // word导入提交
    handleUploadword() {
      if (this.wordImportType > 4) {
        this.handleUploadword_old();
      } else {
        const wordPaper = '/api/design/questionWord/importWordNewForPaper'; // Word
        const { fileListword } = this;
        const formData = new FormData();
        let that = this;
        fileListword.forEach((file) => {
          formData.append('excelfile', file);
          formData.append('examId', this.examid);
          formData.append('examType', this.examType);
          formData.append('importType', this.wordImportType);
        });
        this.uploading = true;
        this.loading = true;
        this.$http.post(wordPaper, formData).then((res) => {
          that.fileCountword = 0;
          that.errorListword = [];
          that.uploading = false;
          this.loading = false;
          if (res.code == 1) {
            this.importwordCheck = true;
            this.listCheck = JSON.parse(res.list);
            this.questions = JSON.parse(res.dataJSON);
            console.log(this.questions);
            this.listSocre = res.listSocre;
            this.listSocre_check = res.listSocre_check;
            this.wordDataJson = res.dataJSON;
            this.errorNum = res.errorNum;
            this.courseName = res.courseName;
            this.totleError = res.totleError;
          } else if (res.code == -1) {
            this.$message.error(res.msg);
          } else {
            this.$message.error('请求失败，请刷新也页面重试！');
          }
        });
      }
    },
    checkWord() {
      var checkBoxList = this.$refs.checkBox;
      //console.log(list);
      var list = [];
      for (let i = 0; i < checkBoxList.length; i++) {
        list.push(checkBoxList[i].innerHTML.replace(/<\/?span[^>]*>/gi, '').replace(/<!---->/g, ''));
      }
      if (!this.courseName || this.courseName.length == 0) {
        this.$message.error('请输入试题分类名称！');
        return false;
      }
      this.uploading = true;
      this.loading = true;
      this.$http
        .post('/api/design/QuestionWord/importWordNewStrForPaper', {
          body: JSON.stringify(list),
          courseName: this.courseName,
          socreJosn: JSON.stringify(this.listSocre),
          examId: this.examid
        })
        .then((res) => {
          this.fileCountword = 0;
          this.errorListword = [];
          this.uploading = false;
          this.loading = false;
          if (res.code == 1) {
            this.listCheck = [];
            this.questions = [];
            this.listSocre = [];
            this.listSocre_check = [];
            (this.totleError = []), (this.courseName = '');
            this.errorNum = 0;
            this.listCheck = JSON.parse(res.list);
            this.questions = JSON.parse(res.dataJSON);
            this.wordDataJson = res.dataJSON;
            this.listSocre = res.listSocre;
            this.listSocre_check = res.listSocre_check;
            this.errorNum = res.errorNum;
            this.courseName = res.courseName;
            this.totleError = res.totleError;
          } else if (res.code == -1) {
            this.$message.error(res.msg);
          } else {
            this.$message.error('请求失败，请刷新也页面重试！');
          }
        });
    },
    del(index) {
      this.listSocre.splice(index, 1);
    },
    add() {
      this.listSocre.push({
        Title: '',
        Num: '',
        Score: '',
        TotleScore: '',
        Error: ''
      });
    },
    upWord() {
      this.uploading = true;
      this.loading = true;
      this.$http
        .post('/api/design/QuestionWord/importWordNewJSONForPaper', {
          data: this.wordDataJson,
          courseName: this.courseName,
          socreJosn: JSON.stringify(this.listSocre),
          examId: this.examid,
          importType: this.wordImportType,
          examType: this.examType
        })
        .then((res) => {
          this.fileCountword = 0;
          this.errorListword = [];
          this.uploading = false;
          this.loading = false;
          let that = this;
          if (res.code == 1) {
            this.listCheck = [];
            this.questions = [];
            this.errorNum = 0;
            this.wordDataJson = [];
            this.importwordCheck = false;
            that.importword = false;
            that.$message.success(res.msg);
            !this.stepMode && that.$router.back();
            that.$parent.getExamStatus(2);
            this.getType();
          } else {
            this.$message.error(res.msg);
          }
        });
    },
    // word导入提交
    handleUploadword_old() {
      const excelPaper = '/api/design/questionbank/importExcelPaper'; // Excel
      const wordPaper = '/api/design/question/importWordForExam'; // Word
      const { fileListword } = this;
      const formData = new FormData();
      let that = this;
      fileListword.forEach((file) => {
        formData.append('excelfile', file);
        formData.append('examId', this.examid);
        formData.append('examType', this.examType);
        formData.append('importType', this.wordImportType);
      });
      this.uploading = true;
      this.loading = true;
      this.$http.post(this.wordImportType > 4 ? excelPaper : wordPaper, formData).then((res) => {
        that.fileCountword = 0;
        that.errorListword = [];
        that.uploading = false;
        this.loading = false;
        if (res.code > 0) {
          that.importword = false;
          that.$message.success(res.msg);
          !this.stepMode && that.$router.back();
          that.$parent.getExamStatus(2);
          this.getType();
        } else {
          that.$message.error(res.msg);
          if (res.list && res.list.length) {
            res.list.forEach((item, index) => {
              if (this.wordImportType > 4) {
                that.errorListword.push({
                  Title: item,
                  Number: index + 1
                });
              } else {
                that.errorListword.push({
                  Title: item.LineNo + item.ErrorInfo,
                  Number: index + 1
                });
              }
            });
          }
        }
      });
    },
    // 获取考试Id
    getType() {
      this.getSecondData();
      this.GetOperationList('examId', this.examid).then((rst) => {
        if (rst.code == 1) {
          this.examTitle = rst.examTitle;
          this.batchTitle = rst.batchTitle;
          if (rst.list.length) {
            rst.list.forEach((item) => {
              if (item.IsWrite || item.IsRead) {
                item.Name === '设置题目' && !item.IsWrite && (this.onlyQuesRead = true);
                this.operationList.push(item.Name);
              }
            });
          }
        } else {
          this.$message.error(rst.msg);
        }
      });
    },
    // 获取试卷信息页面
    getSecondData() {
      const urlApi = '/api/design/papermanage/getSecondData';
      const prames = { examId: this.examid, examType: this.examType };
      let that = this;
      this.$http.post(urlApi, prames).then((res) => {
        let courseList = res.courseList.map((v) => {
          return {
            ...v,
            ruleKnowledgeList: []
          };
        });
        if (res.code == 1) {
          that.paperTypeList = courseList;
          that.paperType = courseList.filter((item) => item.IsCheck === true);
          if (res.examInfo !== null) {
            if (res.examInfo.ZtWay == 2) {
              that.mode = 2;
              switch (res.examInfo.wordImportType) {
                case 1:
                  this.fixedPlaceholder = this.selectData[0].Title;
                  this.wordImportType = this.selectData[0].Id;
                  break;
                case 2:
                  this.fixedPlaceholder = this.selectData[1].Title;
                  this.wordImportType = this.selectData[1].Id;
                  break;
                case 3:
                  this.fixedPlaceholder = this.selectData[2].Title;
                  this.wordImportType = this.selectData[2].Id;
                  break;
                case 5:
                  this.fixedPlaceholder = this.selectData[3].Title;
                  this.wordImportType = this.selectData[3].Id;
                  break;
                case 6:
                  this.fixedPlaceholder = this.selectData[4].Title;
                  this.wordImportType = this.selectData[4].Id;
                  break;
              }
            } else {
              if (res.ruleType == 2) {
                that.mode = 1;
              }
              if (res.ruleType == 1) {
                that.mode = 0;
              }
            }
            that.way = res.examInfo.MultiScoreWays;
            that.randomExamRuleId = res.examInfo.RandomExamRuleId;
            that.paperNumber = res.examInfo.PaperCount;
            that.totalScore = res.totalScore;
            // 编辑禁用状态
            that.editDisabled = res.isAdd;
            that.isAdd = res.isAdd;
            this.getRuleMamageList();
            this.getPaperIsCanEdit();

            if (res.ruleType == 2) {
              that.getRule();
            }
          }
        } else {
          that.$message.error(res.msg);
        }
      });
    },
    // 获取规则列表
    getRuleMamageList() {
      const urlApi = '/api/design/examrules/getCanUseExamRuleList';
      const prames = { ruleName: this.rule, examScore: this.totalScore };
      let that = this;
      this.$http.post(urlApi, prames).then((res) => {
        if (res.code == 1) {
          that.ruleList = res.list;
        }
      });
    },
    // 获取规则详情列表
    getRule() {
      const urlApi = '/api/design/examrules/getQuestionClassList';
      const prames = { randomExamRuleId: this.randomExamRuleId };
      let that = this;
      this.$http.post(urlApi, prames).then((res) => {
        let courseList = res.courseList.map((v) => {
          return {
            ...v,
            ruleKnowledgeList: []
          };
        });
        if (res.code == 1) {
          // that.paperTypeList = courseList;
          that.paperTypeList = courseList.filter((item) => item.IsCheck === true);
          that.paperType = courseList.filter((item) => item.IsCheck === true);
          if (res.ruleInfo !== null) {
            that.examName = res.ruleInfo.RuleTitle;
            that.remarks = res.ruleInfo.Remarks;
            that.way = res.ruleInfo.MultiScoreWays;
          }
        } else {
          that.$message.error(res.msg);
        }
      });
    },
    // 选择规则（随机出题）
    onChangeRulesOptions(value) {
      this.randomPlaceholder = value.label;
      this.randomExamRuleId = value.key;
      this.getRule();
    },
    // 选择难度
    onChangeDifficulty(value) {
      this.selectPlaceholder = value.label;
      if (value.key == 0) {
        this.defficultyLevel = '';
      } else {
        this.defficultyLevel = value.key;
      }
      this.getQuestionsList();
    },
    // 选择知识点
    onChangeKnowledge(value) {
      this.handKnowledgeId = value;
      this.getQuestionsList();
    },
    // 获取考题列表
    getQuestionsList() {
      this.loading = true;
      let that = this;
      let courseIdsStr = this.courseIds.join('/');
      const urlApi = '/api/design/papermanage/getQuesList';
      const prames = {
        randomExamRuleId: this.randomExamRuleId,
        examId: this.examid,
        questionType: this.questionType,
        courseIds: courseIdsStr,
        knowledgeId: this.handKnowledgeId,
        defficultyLevel: this.defficultyLevel,
        title: this.searchValue,
        pageSize: 10, //每页多少条
        page: 1, //每页多少条
      };
      this.$http.post(urlApi, prames).then((res) => {
        this.loading = false;
        that.questionsList = [];
        if (res.code == 1) {
          if (res.list.length) {
            let list = res.list.filter((item) => !that.selectList.some((ele) => ele.Id === item.Id));
            list.forEach((item, index) => {
              let time = item.StartTime + '--' + item.EndTime;
              let key = (res.pagination.pageIndex - 1) * res.pagination.pageSize + index + 1;
              that.questionsList.push({
                ...item,
                time,
                key
              });
            });
          }
          that.defaultSelected();
        }
      });
    },
    // 删除考题
    onDelRule(record, index, indent, expanded) {
      this.$confirm({
        title: '提示',
        content: '你确定要删除该考题吗？',
        centered: true,
        onOk: () => {
          this.selectList.splice(indent, 1);
          this.setNumber[this.setNumberIndex].list = this.selectList;
          this.$message.success('删除成功');
        }
      });
    },
    // 获取知识点列表
    getRuleKnowledgeData(id, index) {
      const urlApi = '/api/design/examrules/getRuleKnowledgeData';
      const prames = { courseId: id, randomExamRuleId: this.randomExamRuleId };
      let that = this;
      this.$http.post('/api/design/knowledgetree/getAllKnowledgeTreeList', {
        courseId: id, //分类Id
        randomExamRuleId: this.randomExamRuleId //考试规则Id
      })
      .then((res) => {
        if (res.code > 0) {
          that.paperType[index].ruleKnowledgeList = res.knowledgeList;
          let list = { knowledgeIds: res.checkedKnowledgeIds, defficultys: [] };
          list.defficultys = res.defficultyLevel ? res.defficultyLevel.split(',').map(Number) : [1, 2, 3, 4, 5];
          that.getQuesTypeCount(id, index, list);
        } else {
          this.$message.error(res.msg);
        }
      });
    },

    // 手动出题获取知识点列表
    getHandKnowList(courseIds) {
      const urlApi = '/api/design/PaperManage/getKonwledgeList';
      const prames = { courseIds: courseIds };
      let that = this;
      this.$http.post(urlApi, prames).then((res) => {
        if (res.questionKnowledgeList.length) {
          that.handKnowledgeList = res.questionKnowledgeList;
        }
      });
      let list = [];
      if (courseIds.length > 0) {
        for (let i = 0; i < courseIds.length; i++) {
          this.$http.post('/api/design/knowledgetree/getAllKnowledgeTreeList', {
            courseId: courseIds[i], //分类Id
            randomExamRuleId: this.randomExamRuleId //考试规则Id
          })
          .then((res) => {
            this.manualList[i].list = res.knowledgeList;
          })
        };
      };
      
    },
    // 循环获取详情
    getFor(array) {
      let that = this;
      let courseIds = array.map((v) => v.Id);
      this.manualList = [];
      for (let i = 0; i < array.length; i++) {
        this.manualList[i] = {
          Id: array[i].Id,
          Name: array[i].Name,
          treeShow: false,
          list: []
        }
      }
      this.courseIds = courseIds;
      if (this.mode == 2) {
        let list = { knowledgeIds: [], defficultys: [] };
        if (this.paperType.length) {
          that.getHandKnowList(courseIds);
          that.getQuesTypeCount(courseIds, 0, list);
        } else {
          that.getHandQuesCount();
        }
      } else {
        for (var i = 0; i < array.length; i++) {
          that.getRuleKnowledgeData(array[i].Id, i);
        }
      }
    },
    // 获取题目列表信息
    async getQuesTypeCount(courseId, index, list) {
      const urlApi = '/api/design/papermanage/getQuesTypeCount';
      let defficultys = list.defficultys ? list.defficultys.join(',') : '1,2,3,4,5';
      // let onLineKnowledgeIds = list.knowledgeIds ? list.knowledgeIds.join(',') : '';
      let onLineKnowledgeIds = list.knowledgeIds;
      let ztWay = this.mode == 2 ? 2 : 4;
      const prames = {
        randomExamRuleId: this.randomExamRuleId,
        courseId: this.mode == 2 ? '' : courseId,
        examId: this.examid,
        cIdList: this.mode == 2 ? courseId.toString() : '',
        examType: this.examType,
        defficultys,
        onLineKnowledgeIds,
        ztWay,
        dataSource: this.wordImportType
      };
      let that = this;
      this.loading = true;
      await this.getHandQuesCount();
      this.$http.post(urlApi, prames).then((res) => {
        this.loading = false;
        if (res.code == 1) {
          if (that.mode == 2) {
            let total = 0;
            for (var i = 0; i < res.list.length; i++) {
              if (res.list[i].QuesList.length > 0) {
                that.setNumber[i].list = res.list[i].QuesList;
                for (var n = 0; n < res.list[i].QuesList.length; n++) {
                  that.setNumber[i].list[n].Id = res.list[i].QuesList[n].QuestionId;
                  that.setNumber[i].list[n].Name = res.list[i].QuesList[n].CourseName;
                  that.setNumber[i].list[n].Title = res.list[i].QuesList[n].Title;
                  that.setNumber[i].list[n].TitleText = res.list[i].QuesList[n].Title;
                  that.setNumber[i].list[n].DefficultyLevel = res.list[i].QuesList[n].DefficultyLevel;
                  that.setNumber[i].list[n].QuesScore = res.list[i].QuesList[n].Score;
                }
                // 手动出题计算总分
                res.list[i].QuesList.forEach(function(val) {
                  that.setNumber[i].total += val.Score;
                });
                if (!that.setNumber[i].score) {
                    that.setNumber[i].score = that.setNumber[i].total/that.setNumber[i].list.length;
                  }
              }
            }
          } else {
            that.paperType[index].data = that.arrRegroup(res, courseId);
            that.questionNumber = that.questionNumber.concat(res.list);
            that.paperType[index].knowledgeIds = list.knowledgeIds;
            that.paperType[index].knowledgeTitles = res.knowledgeTitles;
            that.paperType[index].defficultys = list.defficultys ? list.defficultys : [1, 2, 3, 4, 5];
            that.listeningTrigger = !that.listeningTrigger;
            that.randomExamRuleId = res.randomExamRuleId;
          }
        } else {
          that.$message.error(res.msg);
        }
      });
    },
    // 手动出题题型数量
    getHandQuesCount() {
      const urlApi = '/api/design/papermanage/getQuesCount';
      const prames = { courseIds: this.courseIds };
      return this.$http.post(urlApi, prames).then((res) => {
        this.setNumber = res.list.map((v) => {
          return { ...v, total: 0, score: 0, list: [] };
        });
      });
    },
    // 新增 || 查看考题列表题
    onModification(questionType, type, index) {
      if (this.courseIds.length < 1) {
        return this.$message.error('题目分类不能为空');
      }
      this.questionType = questionType;
      this.setNumberIndex = index;
      this.modalVisible = true;
      this.selectList = [];
      if (this.setNumber[index].list.length > 0) {
        this.setNumber[index].list.forEach((item, idex) => {
          let Number = idex + 1;
          this.selectList.push({
            ...item,
            Number
          });
        });
        console.log(this.selectList);
        // this.selectList = JSON.parse(JSON.stringify(this.setNumber[index].list));
      } else {
        this.selectList = [];
      }
      switch (type) {
        case 'add':
          this.modalTitle = '新增考题';
          this.isShowAddQuestion = true;
          this.selectedRowKeys = [];
          this.defficultyLevel = [];
          this.handKnowledgeId = [];
          this.selectList = this.setNumber[index].list;
          this.getQuestionsList();
          this.selectPlaceholder = '选择难度';
          this.selectKnowledgePlaceholder = '选择知识点';
          this.searchValue = '';
          break;
        case 'lookover':
          this.isShowAddQuestion = false;
          this.modalTitle = '查看已选考题';
          break;
      }
    },
    // 设置考题分数
    onChangeScore(index, value) {
      let newScoreArray = JSON.parse(JSON.stringify(this.setNumber[index].list));
      this.setNumber[index].list = newScoreArray.map((v) => {
        return { ...v, QuesScore: value };
      });
    },
    // 保存试卷
    onSave(quesJson, randomPaperCount) {
      if (!this.operationList.includes('设置题目')) {
        this.$message.warn('您没有权限设置题目');
        return;
      }
      const urlApi = '/api/design/papermanage/saveSecondQues';
      this.loading = true;
      this.paperNumber = randomPaperCount;
      const params = {
        randomExamRuleId: this.randomExamRuleId,
        examId: this.examid,
        ztWay: this.mode == 2 ? 2 : 4,
        randomPaperCount: randomPaperCount ? randomPaperCount : 1,
        quesJson,
        multiScoreWays: this.way,
        examType: this.examType,
        wordImportType: this.wordImportType
      };
      let that = this;
      this.$http.post(urlApi, params).then((res) => {
        this.loading = false;
        if (res.code == 1) {
          that.$message.success(res.msg);
          that.isAdd = true;
          if (this.sysType == 2) {
            that.$router.back();
          } else {
            if (this.stepMode) {
              that.$parent.getExamStatus(2);
              that.$parent.nextStep();
            } else {
              that.$router.back();
            }
          }
        } else {
          that.$message.error(res.msg);
        }
      });
    },
    // 取消
    onCancel() {
      this.paperType = [];
    },
    // 出题方式
    getModeType() {
      this.randomPlaceholder = '从规则中选择';
      this.fixedPlaceholder = '从固定出题中选择';
      this.wordImportType = undefined;
      this.paperType = [];
      this.manualList = [];
      if (this.mode === 0) {
        this.getSecondData();
      }
      if (this.mode === 2) {
        this.fixedPlaceholder = this.selectData[0].Title;
        this.wordImportType = 1
      }
      if (this.editDisabled == false) {
        this.randomExamRuleId = '';
      }
    },
    getCheckbox() {
      if (this.labelShow) {
        this.labelShow = false;
        this.btnTitle = '展开';
      } else {
        this.labelShow = true;
        this.btnTitle = '收起';
      }
    },
    // 补考用
    getTab(type) {
      this.paperType = [];
      this.paperNumber = 1;
      this.examType = type;
      this.mode = 0;
      this.getSecondData();
      this.randomPlaceholder = '从规则中选择';
      this.fixedPlaceholder = '从固定出题中选择';
    },
    // modal 保存
    onModalVisible(state, type) {
      this.searchValue = '';
      switch (state) {
        case 'ok':
          if (!type) {
            let total = 0;
            for (let i = 0; i < this.selectList.length; i++) {
              total = total + parseInt(this.selectList[i].QuesScore);
            }
            this.setNumber[this.setNumberIndex].list = this.selectList;
            this.setNumber[this.setNumberIndex].total = total;
          } else {
            this.setNumber[this.setNumberIndex].list = this.setNumber[this.setNumberIndex].list.concat(this.mergedList);
          }
          break;
        case 'cancel':
          if (type) {
            this.selectList = [];
            this.selectedRowKeys = [];
          }
          break;
      }
      this.modalVisible = false;
    },
    // 选中数据
    onSelectChange(selectedRowKeys, selectedRows) {
      console.log('selectedRowKeys');
      console.log(selectedRowKeys);
      console.log('selectedRows');
      console.log(selectedRows);
      this.selectedRowKeys = selectedRowKeys;
      let newSelectedArray = selectedRows.map((v) => {
        return {
          ...v,
          QuestionId: v.Id,
          QuesScore: 0
        };
      });
      this.mergedList = this.replacementValues(newSelectedArray, this.setNumber[this.setNumberIndex].list);
      //this.setNumber[this.setNumberIndex].list = mergedList;
    },
    // 选题替换相同时保留值 newSelectList//最新选中题目（没有设置分数） oldSelectList// 已经选中过的题目
    replacementValues(newSelectList, oldSelectList) {
      for (let n = 0; n < oldSelectList.length; n++) {
        for (let i = 0; i < newSelectList.length; i++) {
          if (oldSelectList[n].Id == newSelectList[i].Id && oldSelectList[n].QuesScore > 0) {
            newSelectList[i].QuesScore = oldSelectList[n].QuesScore;
          }
        }
      }
      return newSelectList;
    },
    // 手动出题默认选中
    defaultSelected() {
      let index = -1;
      let questionsIds = this.questionsList.map((v) => {
        return v.Id;
      });
      let selectIds = this.selectList.map((v) => {
        return v.Id;
      });
      for (var i = 0; i < selectIds.length; i++) {
        index = questionsIds.indexOf(selectIds[i]);
        if (index > -1) {
          this.selectedRowKeys.push(index);
        }
      }
    },
    // 展示数据data
    arrRegroup(res, courseId) {
      let mainArray = [
        {
          title: '单选题',
          subTitle: '(客观)',
          questionType: 1,
          total: 0,
          count: 10,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '多选题',
          subTitle: '(客观)',
          questionType: 2,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '判断题',
          subTitle: '(客观)',
          questionType: 3,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '填空题',
          subTitle: '(客观)',
          questionType: 4,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '填空题',
          subTitle: '(主观)',
          questionType: 5,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '问答题',
          subTitle: '(主观)',
          questionType: 6,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '匹配题',
          subTitle: '(客观)',
          questionType: 7,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '阅读理解',
          subTitle: '(客观)',
          questionType: 8,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '完形填空',
          subTitle: '(客观)',
          questionType: 9,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '视听题',
          subTitle: '(客观)',
          questionType: 11,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '阅读理解',
          subTitle: '(主观)',
          questionType: 12,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        },
        {
          title: '完形填空',
          subTitle: '(主观)',
          questionType: 13,
          total: 0,
          count: 0,
          randomQuesNumber: 0,
          randomQuesScore: 0,
          courseId: '',
          onLineKnowledgeIds: '',
          onLineKnowledgeTitles: '',
          defficultys: ''
        }
      ];
      let mergeArray = res.list;
      for (var n = 0; n < mainArray.length; n++) {
        for (var i = 0; i < mergeArray.length; i++) {
          if (mergeArray[i].QuestionType == mainArray[n].questionType) {
            mainArray[n].randomQuesNumber = mergeArray[i].ChooseCount;
            mainArray[n].randomQuesScore = mergeArray[i].ChooseScore;
            mainArray[n].count = mergeArray[i].Count;
          }
        }
        mainArray[n].total = mainArray[n].randomQuesNumber * mainArray[n].randomQuesScore;
      }
      return mainArray;
    }
  }
};
</script>

<style lang="scss">
</style>
